#ifndef PCG_CACHE_H
#define PCG_CACHE_H

#include "noise.h"

/*!
@header Cache
Description forthcoming.
@copyright James Callender
@updated 2007-02-09
*/

/*!
Convenience macro for accessing points within the cache structure
*/
#define pcg_cache_at1(c, x) (c->data[x])
/*!
Convenience macro for accessing points within the cache structure
*/
#define pcg_cache_at2(c, x, y) (c->data[(y)*c->size[0] + x])
/*!
Convenience macro for accessing points within the cache structure
*/
#define pcg_cache_at3(c, x, y, z) (c->data[(z)*c->size[0]*c->size[1] + (y)*c->size[0] + x])

/*!
This structure is used to store the result of a block of noise of up to 3 dimensions.
*/
typedef struct {
	unsigned int size[3];
	float *data;
} pcg_cache_t;

/*!
Allocates a cache object with the specified width, height, and depth.
*/
pcg_cache_t *pcg_cache_create(unsigned int width, unsigned int height, unsigned int depth);

/*!
Deletes cache object and all resources held by it.
*/
void pcg_cache_delete(pcg_cache_t *cache);

/*!
Fills the cache with a 1-dimensional noise function.
*/
void pcg_cache_fill1(pcg_cache_t *cache, pcg_noise1_fn_t prim, int iz, int iy, float xo, float xs);

/*!
Fills the cache with a 2-dimensional noise function.
*/
void pcg_cache_fill2(pcg_cache_t *cache, pcg_noise2_fn_t prim, int iz, float xo, float yo, float xs, float ys);

/*!
Fills the cache with a 3-dimensional noise function.
*/
void pcg_cache_fill3(pcg_cache_t *cache, pcg_noise3_fn_t prim, float xo, float yo, float zo, float xs, float ys, float zs);

/*!
Use spherical coordinates to map a 3-dimensional noise function to 2-dimensional space.
*/
void pcg_cache_fill_spheremap(pcg_cache_t *cache, pcg_noise3_fn_t prim, int iz, float xo, float yo, float zo, float r);

#endif // PCG_CACHE_H